package com.yang.action;

import com.yang.entity.Orders;
import com.yang.service.OrdersService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/updateOrders")
public class OrdersUpdateAction extends HttpServlet {
    OrdersService ordersService = new OrdersService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Orders orders = new Orders();
        String id = req.getParameter("id");
        orders.setId(id);
        String username = req.getParameter("username");
        orders.setUsername(username);
        String address = req.getParameter("address");
        orders.setAddress(address);
        String creationtime = req.getParameter("creationtime");
        orders.setCreationtime(Date.valueOf(creationtime));
        String tel = req.getParameter("tel");
        orders.setTel(tel);
        String totalamount = req.getParameter("totalamount");
        String status = req.getParameter("status");
        orders.setStatus(Integer.parseInt(status));
        String userid = req.getParameter("userid");
        orders.setUserid(Integer.parseInt(userid));
        int num = ordersService.updateOrdersById(orders);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

